var userAjax;

function loginListener(){
	var obj = validResponse(userAjax);
	if (obj != undefined){
		if(obj.loginResult == true)
			setLoggedin(obj.displayName);
		else
			setUnLogged(false);
	}
}


function checkAlreadyLoggedIn(){
	userAjax = fire("POST","Login",new Object(),loginListener);
}

checkAlreadyLoggedIn();

function userLogin(params){
	userAjax = fire("POST","Login",params,loginListener);
}

function unauthorized(){
	setUnLogged(true);
}

//register methods 

function newUser(params){
	userAjax = fire("POST","Register",params,newUserCallback);
}

function newUserCallback(){
	var obj = validResponse(userAjax);
	if (obj != undefined){
		if(obj.result == true){
			returnToHome();
		}else{
			registrationError(obj.errorMessage);
		}
	}
}

